pub trait FractalIterator {
	type Item;
	fn for_each(self, f: &mut impl FnMut(Self::Item) -> bool) -> bool;
	fn collect<F: FromFractalIterator<Self::Item>>(self) -> F
	where
		Self: Sized,
	{
		FromFractalIterator::from_internal_iter(self)
	}
}
impl<I: Iterator> FractalIterator for I {
	type Item = I::Item;
	fn for_each(self, f: &mut impl FnMut(Self::Item) -> bool) -> bool {
		for item in self {
			if !f(item) {
				return false;
			}
		}
		true
	}
}

pub trait IntoFractalIterator {
	type Item;
	type IntoInternalIter: FractalIterator<Item = Self::Item>;
	fn into_internal_iter(self) -> Self::IntoInternalIter;
}
impl<I: FractalIterator> IntoFractalIterator for I {
	type Item = <Self as FractalIterator>::Item;
	type IntoInternalIter = Self;
	fn into_internal_iter(self) -> Self::IntoInternalIter {
		self
	}
}

pub trait FromFractalIterator<T> {
	fn from_internal_iter<I: IntoFractalIterator<Item = T>>(iter: I) -> Self;
}
impl<T> FromFractalIterator<T> for Vec<T> {
	fn from_internal_iter<I: IntoFractalIterator<Item = T>>(iter: I) -> Self {
		let mut vec = Vec::new();
		iter.into_internal_iter().for_each(&mut |item| {
			vec.push(item);
			true
		});
		vec
	}
}

// pub trait ExtendFromInternalIterator<T> {
// 	/// Extends `self` with each item of `internal_iter`.
// 	fn extend_from_internal_iter<I>(&mut self, internal_iter: I)
// 	where
// 		I: IntoInternalIterator<Item = T>;
// }

// impl<T> ExtendFromInternalIterator<T> for Vec<T> {
// 	fn extend_from_internal_iter<I>(&mut self, internal_iter: I)
// 	where
// 		I: IntoInternalIterator<Item = T>,
// 	{
// 		internal_iter.into_internal_iter().for_each(&mut |item| {
// 			self.push(item);
// 			true
// 		});
// 	}
// }
